//生成菜单
var menuItem = Vue.extend({
    name: 'menu-item',
    props: {item: {}},
    template: [
    	'<li class="menuList">',
    	'<a href="javascript:;">',
    	'<i class="iconfont">&#xe723;</i>',
    	'<cite>{{item.name}}</cite>',
    	'<i class="iconfont nav_right">&#xe697;</i>',
    	'</a>',
    	'<ul class="sub-menu">',
    	'<li v-for="child in item.childs">',
    	'<a v-bind:_href="staticURL+child.url">',
    	'<i class="iconfont">&#xe6a7;</i>',
    	'<cite>{{child.name}}</cite>',
    	'</a>',
    	'</li >',
    	'</ul>',
    	'</li>'
    ].join('')
});

//注册菜单组件
Vue.component('menuItem', menuItem);
var vm = new Vue({
    el: '#layout',
    data: {
        menuList: {}
    },
    methods: {
        getMenuList: function () {
            $.getJSON(staticURL+"/login/meneuList", function (r) {
                vm.menuList = r.resourceList;
            });
        },
        updatePassword: function () {
      	  layer.prompt({title: '请输入新密码', formType: 1}, function(pwd1, index){
    	  	  layer.close(index);
    		  layer.prompt({title: '请确认新密码', formType: 1}, function(pwd2, index){
    		    layer.close(index);
    		    if(pwd1==pwd2){
    		    	$.post(staticURL+"/basic/userInfoAction/editPassword.do?password="+pwd2, function(msg) {
    		    		layer.msg('恭喜，密码修改成功！');
    		    	});
    		    }else{
    			    layer.msg('您两次输入的密码不一致！');
    		    }
    		  });
    		});
        },
        logout: function (){
      	  layer.confirm('您确定要退出系统?', {
    		  btn: ['确定','取消'] //按钮
    		}, function(){
    			location.href = staticURL+"/login/logout.do";
    		}, function(){
    	  	}
    	  );
        }
        ,goFrontend:function(){
        	window.open(staticURL+"/frontend")
        }
    },
    created: function () {
        this.getMenuList();
    },updated:function(){
    	//在这里绑定左侧菜单的各种事件
    	xadmin();
    	layui.use(['layer','element'],
  		    function() {
		        window.layer = layui.layer;
		        layer = layui.layer;
  		    });
    }
});